home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Button / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.4 KB  |  183 lines  |  [TEXT/CWIE]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FRAME_H
  13. #include "Frame.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef BEHAVIOR_H
  21. #include "Behavior.h"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. // ----- Framework -----
  29.  
  30. #ifndef FWBUTTON_H
  31. #include "FWButton.h"
  32. #endif
  33.  
  34. #ifndef FWPRESEN_H
  35. #include "FWPresen.h"
  36. #endif
  37.  
  38. #ifndef FWCONTXT_H
  39. #include "FWContxt.h"
  40. #endif
  41.  
  42. #ifndef FWDRCMD_H
  43. #include "FWDrCmd.h"
  44. #endif
  45.  
  46. #ifndef FWRECSHP_H
  47. #include "FWRecShp.h"
  48. #endif
  49.  
  50. // ----- OpenDoc -----
  51.  
  52. #ifndef SOM_ODFocusSet_xh
  53. #include <FocusSet.xh>
  54. #endif
  55.  
  56. //========================================================================================
  57. //    Runtime information
  58. //========================================================================================
  59.  
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment odfbutton
  62. #endif
  63.  
  64. //========================================================================================
  65. //    class CButtonFrame
  66. //========================================================================================
  67.  
  68. FW_DEFINE_AUTO(CButtonFrame)
  69. FW_DEFINE_CLASS_M2(CButtonFrame, FW_CFrame, FW_MReceiver)
  70.  
  71. //----------------------------------------------------------------------------------------
  72. //    CButtonFrame::CButtonFrame
  73. //----------------------------------------------------------------------------------------
  74.  
  75. CButtonFrame::CButtonFrame(Environment* ev, 
  76.                     ODFrame* frame, 
  77.                     FW_CPresentation* presentation, 
  78.                     FW_CPart* part,
  79.                     CButtonContent* content) :
  80.     FW_CFrame(ev, frame, presentation, part),
  81.     FW_MDroppableFrame(ev, this),
  82.     fOptionBehavior(NULL),
  83.     fCurrentFocusSet(NULL),
  84.     fContent(content)
  85. {        
  86.     ChangeDroppableState(ev, FW_kFrameDroppable);    // Only droppable in view as frame
  87.     
  88.     FW_END_CONSTRUCTOR
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. //    CButtonFrame::~CButtonFrame
  93. //----------------------------------------------------------------------------------------
  94.  
  95. CButtonFrame::~CButtonFrame()
  96. {
  97.     FW_START_DESTRUCTOR
  98.     
  99.     delete fCurrentFocusSet;
  100. }
  101.  
  102. //----------------------------------------------------------------------------------------
  103. //    CButtonFrame::PostCreateViewFromStream
  104. //----------------------------------------------------------------------------------------
  105. // PostCreateViewFromStream is called after subviews are created from resources.  
  106. // Add code which cannot be handled by current resource types.
  107.  
  108. void CButtonFrame::PostCreateViewFromStream(Environment* ev)
  109. {
  110.     // ----- Add a behavior to our button
  111.     FW_CView* view = FindViewByID(ev, 1);
  112.     FW_CButton* button = FW_DYNAMIC_CAST(FW_CButton, view);
  113.     FW_ASSERT(button != NULL);
  114.  
  115.     // Add the button as the notifier for the content object
  116.     fContent->AddInterest(button, FW_kButtonPressedMsg);
  117.     
  118.     //     The role of the COptionBehavior is to detect Option-Click (In this case change the focus
  119.     //    set of the frame). Having a behavior allows us to not have to subclass FW_CButton.
  120.     fOptionBehavior = FW_NEW(COptionBehavior, (ev));
  121.     button->AdoptEventHandler(ev, fOptionBehavior);
  122.  
  123.     fCurrentFocusSet = fOptionBehavior->GetDesiredFocusSet();
  124.     
  125.     // WARNING: Make sure that classes created from resources won't be dead-stripped
  126.     FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
  127.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //    CButtonFrame::Draw
  132. //----------------------------------------------------------------------------------------
  133.  
  134. void CButtonFrame::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
  135. {
  136.     FW_CViewContext fc(ev, NULL, facet, invalidShape);
  137.     
  138.     // Just erase before the button draws itself
  139.     FW_CRect invalidRect;
  140.     fc.GetClipRect(invalidRect);
  141.     FW_CRectShape::RenderRect(fc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. //     CButtonFrame::RequestFocusSet
  146. //----------------------------------------------------------------------------------------
  147. //    Set the fCurrentFocusSet to DesiredFocusSet. FW_CFrame::RequestFocusSet will call our CButtonFrame::GetFocusSet
  148.  
  149. FW_Boolean CButtonFrame::RequestFocusSet(Environment *ev)
  150. {
  151.     fCurrentFocusSet = fOptionBehavior->GetDesiredFocusSet();
  152.     
  153.     return FW_CFrame::RequestFocusSet(ev);
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. //    CButtonFrame::GetFocusSet
  158. //----------------------------------------------------------------------------------------
  159. //    Usually GetFocusSet simply returns the presentation's focusSet. But here we want to 
  160. //    have one focusSet per frame instead of one per presentation.
  161.  
  162. ODFocusSet* CButtonFrame::GetFocusSet(Environment* ev) const
  163. {
  164. FW_UNUSED(ev);
  165.  
  166.     return fCurrentFocusSet;
  167. }
  168.  
  169. //----------------------------------------------------------------------------------------
  170. //    CButtonFrame::NewDropCommand
  171. //----------------------------------------------------------------------------------------
  172.  
  173. FW_CDropCommand* CButtonFrame::NewDropCommand(Environment *ev, 
  174.                                     FW_CFrame* frame,
  175.                                     ODDragItemIterator* dropInfo, 
  176.                                     ODFacet* facet, 
  177.                                     const FW_CPoint& dropPoint)
  178. {
  179.  
  180.     return FW_NEW(FW_CDropCommand, (ev, frame, dropInfo, facet, dropPoint, FW_kCantUndo));
  181. }
  182.  
  183.